Skip to content

feat(storage): tenant-scoped trace_id uniqueness (RAN-21)#29

Merged
aksOps merged 1 commit into
mainfrom
ran21-trace-id-tenant-scoped
Apr 25, 2026
Merged

feat(storage): tenant-scoped trace_id uniqueness (RAN-21)#29
aksOps merged 1 commit into
mainfrom
ran21-trace-id-tenant-scoped

Conversation

@aksOps

@aksOps aksOps commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Replace Trace.TraceID's standalone uniqueIndex with composite idx_traces_tenant_trace_id on (tenant_id, trace_id) so two tenants can ingest identical trace_ids without either silently dropping into OnConflict.DoNothing.

AutoMigrateModels now idempotently discovers and drops any pre-existing single-column unique index on traces.trace_id (SQLite / Postgres / MySQL / MSSQL), so upgraded databases stop silently blocking cross-tenant reuse on first boot post-RAN-21. Discovery is structure-based — the composite index is two columns and is never matched.

Files

  • internal/storage/models.go — composite uniqueIndex:idx_traces_tenant_trace_id declared on Trace.TenantID (priority 1) and Trace.TraceID (priority 2). Standalone uniqueIndex removed from TraceID.
  • internal/storage/factory.godropLegacyTraceIDUniqueIndex invoked after AutoMigrate in AutoMigrateModels. Failures log but do not abort boot.
  • internal/storage/trace_repo.go — comments tightened on CreateTrace / BatchCreateTraces (per-tenant dedupe semantics) and GetTrace (child Preload now defense-in-depth, not collision protection).
  • internal/storage/migrate_traces.go (new) — per-driver legacy-index discovery; idempotent.
  • internal/storage/trace_tenant_test.go (new) — six acceptance tests, all green on SQLite.

Test plan

  • go vet ./... clean
  • go build ./... clean
  • go test -count=1 ./... — all packages green; 6 new tests cover cross-tenant CreateTrace + BatchCreateTraces, intra-tenant dedupe still works, GetTrace child isolation, legacy-index drop on simulated upgrade, composite index landed on fresh DB.
  • build · vet · test CI check (required) — armed for auto-merge.

Paperclip

Refs RAN-21.

Replace standalone uniqueIndex on Trace.TraceID with composite
idx_traces_tenant_trace_id(tenant_id, trace_id) so two tenants can
ingest the same trace_id without either dropping into OnConflict.DoNothing.
AutoMigrateModels now idempotently discovers and drops any legacy
single-column unique index on traces.trace_id (SQLite/Postgres/MySQL/MSSQL)
so upgraded databases stop silently blocking cross-tenant reuse.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
@aksOps aksOps enabled auto-merge (squash) April 25, 2026 16:04
@sonarqubecloud

Copy link
Copy Markdown

@aksOps aksOps merged commit 402297d into main Apr 25, 2026
11 checks passed
@aksOps aksOps deleted the ran21-trace-id-tenant-scoped branch April 25, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant